<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专业管理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .cont {
            padding: 10px;
        }

        #xz {
            margin-bottom: 10px;
        }

        #tbody td>button:first-child {
            margin-right: 10px;
        }

        #tbody td {
            line-height: 2.42857143;
        }

        #tc {
            position: absolute;
            width: calc(100vw - 20px);
            height: 100vh;
            top: 0px;
            background-color: white;
            display: none;
        }

        #tc>button {
            margin-right: 10px;
        }
    </style>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>
</head>

<body>
    <div class="cont">
        <button class="btn btn-primary m-r-5" id="xz" onclick="tC()" value="11">新增专业</button>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th class="text-center">序号</th>
                    <th class="text-center">专业</th>
                    <th class="text-center">学制</th>
                    <th class="text-center">学分</th>
                    <th class="text-center" id="cZ">操作</th>
                </tr>
            </thead>
            <tbody class="text-center" id="tbody">
            </tbody>
            <tfoot class="text-center">
                <tr>
                    <td colspan="5" id="tdlast">
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <li onclick="syy()">
                                    <a href="#" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                                <li><a href="#" id="yema">1</a></li>
                                <li onclick="xyy()">
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </td>
                </tr>
            </tfoot>
        </table>
        <form id="tc" onsubmit="return false;">
            <div class="h3" id="mc">新增专业</div>
            <div class="form-group">
                <label for="exampleInputEmail1">专业：</label>
                <input type="text" class="form-control" placeholder="专业" id="zhuanye">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">学制：</label>
                <input type="text" class="form-control" placeholder="学制" id="xuezhi">
            </div>
            <div class="form-group">
                <label for="exampleInputFile">学分：</label>
                <input type="text" class="form-control" placeholder="学分" id="xuefen">
            </div>
            <button class="btn btn-primary m-r-5" onclick="xZ()" id="anmc">新增</button><button
                class="btn btn-primary m-r-5" onclick="qX()">取消</button>
        </form>
    </div>
    <script src="../js/pubilc.js"></script>
    <script>
        var fly = -1
        var item = 1
        var id = ''
        var y = 1
        var arr = []
        bd()
        function bd() {
            xhr({
                methods: 'get',
                url: `/user/info?token=${sessionStorage.getItem('token')}`,
                success: function (res) {
                    if (res.role_id != null) {
                        xhr({
                            methods: 'post',
                            url: `/roleSys/getRoleList`,
                            data: JSON.stringify({
                                role_school_id: Number(sessionStorage.getItem('id'))
                            }),
                            success: function (fly) {
                                for (i = 0; i < fly.length; i++) {
                                    if (res.role_id == fly[i].role_id) {
                                        var index = fly[i].role_rank_id
                                        xhr({
                                            methods: 'get',
                                            url: `/rankSys/getRank?school_id=${Number(sessionStorage.getItem('id'))}`,
                                            success: function (l) {
                                                for (j = 0; j < l.length; j++) {
                                                    var ind = xz.value.split('')[0] - 1
                                                    var chaiji
                                                    if (l[j].rank_id == index) {
                                                        if (l[j].rank_sys.length < ind) {
                                                            xz.style.display = 'none'
                                                            cZ.style.display = 'none'
                                                            for (i = 0; i < anN.length; i++) {
                                                                if (anN[i].value == 12) {
                                                                    anN[i].style.display = 'none'
                                                                }
                                                            }
                                                            for (j = 0; j < anN.length; j++) {
                                                                if (anN[j].value == 13) {
                                                                    anN[j].style.display = 'none'
                                                                }
                                                            }
                                                            return
                                                        } else {
                                                            chaiji = l[j].rank_sys[ind].page_function_ids.split(',')
                                                        }
                                                        console.log(chaiji)
                                                        if (chaiji.indexOf('11') == -1) {
                                                            xz.style.display = 'none'
                                                        }
                                                        if (chaiji.indexOf('12') == -1 && chaiji.indexOf('13') == -1) {
                                                            cZ.style.display = 'none'
                                                        }
                                                        if (chaiji.indexOf('12') == -1) {
                                                            for (i = 0; i < anN.length; i++) {
                                                                if (anN[i].value == 12) {
                                                                    anN[i].style.display = 'none'
                                                                }
                                                            }
                                                        }
                                                        if (chaiji.indexOf('13') == -1) {
                                                            for (j = 0; j < anN.length; j++) {
                                                                if (anN[j].value == 13) {
                                                                    anN[j].style.display = 'none'
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                        })
                                    }
                                }
                            }
                        })
                    } else {
                        return
                    }
                }
            })
        }
        biaoG()
        function biaoG() {
            arr = []
            xhr({
                methods: 'get',
                url: `/specialty/get?school_id=${Number(sessionStorage.getItem('id'))}`,
                success: function (res) {
                    tbody.innerHTML = ''
                    var ye = res.slice((item - 1) * 10, (item - 1) * 10 + Number(10))
                    console.log(ye)
                    for (j = 0; j < ye.length; j++) {
                        arr.push(ye[j])
                    }
                    yema.innerHTML = y
                    for (i = 0; i < ye.length; i++) {
                        tbody.innerHTML += `<tr>  
                    <td>${ye[i].specialty_id}</td>
                    <td>${ye[i].specialty_name}</td>
                    <td>${ye[i].specialty_Date}</td>
                    <td>${ye[i].specialty_score}</td>
                    <td><button class="btn btn-primary m-r-5 xiouG" onclick='xg(${i})' value="12">修改</button><button class="btn btn-primary m-r-5 shanC" onclick='sc(${i})' value="13">删除</button></td>
                </tr>`
                    }
                }
            })
        }
        var anN = document.getElementsByTagName('button')
        function syy() {
            if (item <= 1) {
                item = 1
                y = 1
                return
            }
            item--
            y--
            biaoG()
        }
        function xyy() {
            item++
            y++
            biaoG()
        }
        function tC() {
            tc.style.display = 'block'
            mc.innerHTML = '新增专业'
            anmc.innerHTML = '新增'
            fly = -1
        }
        function qX() {
            tc.style.display = 'none'
            zhuanye.value = '', xuezhi.value = '', xuefen.value = ''
        }
        function xZ() {
            if (fly == -1) {
                //新增
                if (zhuanye.value && xuezhi.value && xuefen.value) {
                    xhr({
                        methods: 'post',
                        url: '/specialty/add',
                        data: JSON.stringify({
                            specialty_name: zhuanye.value,
                            specialty_Date: xuezhi.value,
                            specialty_score: xuefen.value,
                            specialty_school_id: Number(sessionStorage.getItem('id'))
                        }),
                        success: function (res) {
                            console.log(res)
                            biaoG()
                            tc.style.display = 'none'
                        }
                    })
                } else {
                    alert('请输入专业、学制、学分')
                }
            } else {
                if (zhuanye.value && xuezhi.value && xuefen.value) {
                    xhr({
                        methods: 'post',
                        url: '/specialty/edit',
                        data: JSON.stringify({
                            specialty_name: zhuanye.value,
                            specialty_Date: xuezhi.value,
                            specialty_score: xuefen.value,
                            specialty_id: Number(id)
                        }),
                        success: function (res) {
                            console.log(res)
                            biaoG()
                            tc.style.display = 'none'
                        }
                    })
                } else {
                    alert('请输入专业、学制、学分')
                }
            }
            zhuanye.value = '', xuezhi.value = '', xuefen.value = ''
        }
        function xg(i) {
            fly = i
            id = arr[i].specialty_id
            anmc.innerHTML = '修改'
            mc.innerHTML = '修改专业'
            zhuanye.value = arr[i].specialty_name
            xuezhi.value = arr[i].specialty_Date
            xuefen.value = arr[i].specialty_score
            tc.style.display = 'block'
        }
        // function sc(i) {
        //     xhr({
        //         methods: 'post',
        //         url: '/application/json',
        //         data: JSON.stringify({
        //             specialty_id: arr[i].specialty_id
        //         }),
        //         success: function (res) {
        //             console.log(res)
        //         }
        //     })
        //     biaoG()
        // }
    </script>
</body>

</html>